<template>
  <div class="flex-content">
    <div class="Login-form">
      <div class="form-title"><span>xxxx管理平台</span></div>
      <el-form
        :model="form"
        label-width="70px"
        :rules="loginRules"
        status-icon
        ref="formRef"
        class="elform-class"
      >
        <el-form-item label="登录名" prop="username">
          <el-input v-model="form.username" type="text" autocomplete="off" />
        </el-form-item>
        <el-form-item label="密&#8195;码" prop="password">
          <el-input
            v-model="form.password"
            type="password"
            autocomplete="off"
            show-password
          />
        </el-form-item>
        <el-button type="primary" @click="onSubmit(formRef)">登录</el-button>
      </el-form>
    </div>
    <div class="footer">
      <span>xxxxx</span>| <span>xxxxx</span>| <span>xxxxx</span>|
      <span>xxxxx</span>
    </div>
  </div>
</template>

<script setup lang="ts">
import type { FormInstance } from "element-plus";
import { reactive, ref } from "vue";
import { useRouter } from "vue-router";

const ruter = useRouter();
// do not use same name with ref
const form = reactive({
  username: "",
  password: "",
});
const formRef = ref<FormInstance>();

const loginRules = reactive({
  username: [{ required: true, message: "请输入用户名", trigger: "blur" }],
  password: [{ required: true, message: "请输入密码", trigger: "blur" }],
});
const onSubmit = async (formEl: FormInstance | undefined) => {
  if (!formEl) return;
  await formEl.validate((valid, fields) => {
    if (valid) {
      ruter.push("/BigScreen");
    } else {
      console.log("error submit!", fields);
    }
  });
};
</script>

<style lang="scss" scoped>
@import "./Login.scss";
</style>
